#include <cmath>
#include <iostream>

#include "point.h"

Point::Point ( ){
	this->x = 0.;
	this->y = 0.;
	this->z = 0.;
    selected = false;
}

Point::Point ( double x, double y, double z ){
	this->x = x;
	this->y = y;
	this->z = z;
    selected = false;
}

Point::Point ( const Point& v ){
	this->x = v.x;
	this->y = v.y;
	this->z = v.z;
    selected = v.selected;
}

Point::~Point(){
}

Point Point::operator-( const Point& v ){
	return Point ( this->x - v.x, this->y - v.y, this->z - v.z );
}

Point Point::operator+( const Point& v ){
	return Point ( this->x + v.x, this->y + v.y, this->z + v.z );
}

Point *Point::operator+( const Point* v ){
	return new Point ( this->x + v->x, this->y + v->y, this->z + v->z );
}

Point Point::operator*(double escalar){
	return Point ( this->x*escalar, this->y*escalar, this->z*escalar );
}

bool Point::operator==(const Point& v){
    if((x == v.x) && (y == v.y) && (z == v.z)) return true;
	else return false;

}

double Point::norm(){
	return sqrt(this->dotProduct(*this));
}

Point Point::normalization(){
	double norm = this->norm();
	return Point(this->x/norm, this->y/norm, this->z/norm);
}

double Point::dotProduct( Point v ){
	return (this->x*v.x) + (this->y*v.y) + (this->z*v.z);
}

Point Point::crossProduct( Point v ){
	return Point ( this->y*v.z - this->z*v.y, this->z*v.x - this->x*v.z, this->x*v.y - this->y*v.x );
}

double Point::area(Point& _p1, Point& _p2){
    Point p0 = *this;
    return (1/2.0)*((_p1 - p0).crossProduct(_p2 - p0)).norm();
}

void Point::show( ) {
	std::cout << "point (  " << x << " ,  " << y << " ,  " << z << "  )" << std::endl;
}

double *Point::intoVector(){
    double *d;
    d = new double[3];
    d[0] = x;
    d[1] = y;
    d[2] = z;

    return d;
}

void Point::select(bool _s){
    selected = _s;
}

bool Point::isSelected(){
    return selected;
}
